package com.lsq.asyndemo.listener;

import com.lsq.asyndemo.event.OrderEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ServiceListener {

    @Async
    @EventListener
    public void handleOrderEvent(OrderEvent event) {
        log.info("监听到订单创建事件：{},{},{}", event.getOrder().getOrderId(), event.getOrder().getPrice(), event.getOrder().getMsg());
        try {
            Thread.sleep(3000L);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
